﻿//登录按钮事件

code();
//验证码
function code() {
    var str = "qwertyuiopasdfghjklzxcvbnm1234567890QWERTYUIOPLKJHGFDSAZXCVBNM";
    var str1 = 0;
    for (var i = 0; i < 4; i++) {
        str1 += str.charAt(Math.floor(Math.random() * 62))
    }
    str1 = str1.substring(1)
    $("#code").html(str1);
}
//验证码刷新
$("#code").click(code);

$("#login_btn").click(function () {
    var name = $("#username").val();
    var pwd = $("#userpwd").val();
    //var cod = $("#code").val();
    var code = $("#code1").val();
    var datas = {};
    datas.Name = name;
    datas.Password = pwd;
    if (name == "") {
        layer.msg("用户名不能为空!", { time: 1000 });
    } else if (name != datas.Name) {
        layer.msg("用户名错误！", { time: 1000 });
    } else if (pwd == "") {
        layer.msg("密码不能为空!", { time: 1000 });
    } else if (pwd != datas.Password) {
        layer.msg("密码错误！", { time: 1000 });
    } else if (code == "") {
        layer.msg("验证码不能为空!", { time: 1000 });
    } else if ($("#code1").val().toLocaleUpperCase() != $("#code").html().toLocaleUpperCase()) {
        layer.msg("验证码错误，不区分大小写!", { time: 1000 });
    } else {
        $.ajax({
            url: "/Login/GetAdminUser?opr=" + true,
            data: datas,
            type: "post",
            success: function (data) {
                if (data.Success) {
                    layer.alert('登录成功！', {
                        title: '提示框',
                        icon: 1,
                    }, location.href = "/Home/Index")

                } else {
                    alert("登录失败！");

                }
            }
        })
    }
    return false;
})